import Roact from "@rbxts/roact";
import { ContainerService } from "shared/component/container/ContainerService";
import Log4R from "shared/component/log/Log4R";
import { StartView } from "../view/StartView";
import Mouter from "shared/component/dlt-view/Mouter";
import { ScrennDisplayOrder } from "shared/enums/ScreenDisplayOrder";
import EventBinder from "shared/component/event/EventBinder";
const loginfo = Log4R.getLog('info');
/** 界面 */
export class DashboardServiceImpl extends ContainerService<Ctn.DashboardService, Ctn.DashboardEntity> implements Ctn.DashboardService {
    protected serverCalls: (keyof this)[] = [];
    protected serviceName: keyof Ctn.Services = "dashboardService";
    startButton?: Roact.Ref<TextButton>;
    shartButtonEventBind = new EventBinder<() => void>();
    onStartButtonClick = this.shartButtonEventBind.bind();
    private transMask(transParency = 1) {
        const maskFrame = this.getPlayerGui().WaitForChild('startMask', 10)?.WaitForChild('Frame', 10) as Frame;
        if (maskFrame?.IsA('Frame')) {
            maskFrame.BackgroundTransparency = transParency;
        } else {
            pcall(() => {
                print("maskFrame", maskFrame)
                throw ("can not get maskframe")
            })
        }
    }
    showStartButton() {
        const startButton = this.startButton?.getValue();
        if (startButton)
            startButton.Visible = true;
        /** 隐藏初始遮罩 */
        this.transMask(1)
    }
    /** 初始遮罩用的screen */
    startScreen?: ScreenGui
    showStartView() {
        if (this.startScreen) {
            this.startScreen.Destroy();
        }
        this.startScreen = new Instance("ScreenGui", this.getPlayerGui());
        this.startScreen.Name = "Start";
        this.startScreen.DisplayOrder = ScrennDisplayOrder.mask;
        this.startScreen.ScreenInsets = Enum.ScreenInsets.None;
        const mounter = new Mouter();
        this.startButton = Roact.createRef<TextButton>()
        mounter.mount(<StartView shartButtonEventBind={this.shartButtonEventBind} mounter={mounter} startButton={this.startButton} ></StartView>, this.startScreen);
        /** 隐藏初始遮罩 */
        this.transMask(1)
    }

}